/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.lottery.game.core.modules.service.app;

import com.lottery.game.common.utils.MakeNoUtil;
import com.lottery.game.common.utils.UUIDUtils;
import com.lottery.game.core.modules.entity.game.GameRoom;
import com.lottery.game.core.modules.entity.user.RoomAds;
import com.lottery.game.core.modules.mapper.RoomDao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * 游戏用户Service
 * @author chenye
 * @version 2018-03-25
 */
@Slf4j
@Service
//@Transactional(readOnly = true)
public class RoomService {

	@Autowired
	private RoomDao roomDao;

	public RoomResult createRoom(String name) {
		String orderNo = MakeNoUtil.makeOrderNum();

		log.info("   ---orderNo: {}", orderNo);

		RoomResult result = new RoomResult("创建房间成功！", "success");
		Integer b = this.roomDao.queryRoomNameCount(name);
		if (b != null && b.longValue() > 0) {
			// 用户名、手机、电子邮件存在
			result = new RoomResult("用户名或者手机已经存在！", "fail");
		}
		this.roomDao.createRoom(UUIDUtils.randomUUID(), name, orderNo);

		return result;
	}
	// 查询用户是否存在

	public List<GameRoom> queryRoomList(Integer start, Integer size) {
		return this.roomDao.queryRoomList(start,size);
	}

	public GameRoom queryRoomByRoomNo(String  roomnumber){
		return this.roomDao.queryRoomByRoomNo(roomnumber);
	}


	/**
	 * 修改轮播图
	 * @param pictureAddress
	 * @param carouseId
	 * @return
	 */
	public int  updateCarouseIconAddress(String pictureAddress,String carouseId) {
		try {
			if(!StringUtils.isEmpty(pictureAddress) && !StringUtils.isEmpty(carouseId)) {
				Map<String, String> paramMap=new HashMap<>();
				paramMap.put("pictureAddress", pictureAddress);
				paramMap.put("carouseId", carouseId);
				return this.roomDao.updateCarouseIconAddress(paramMap);
			}else {
				return 0;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return 0;
	}

	public int addRoom(Map<String, String> map) {
		return this.roomDao.addRoom(map);
	}

	public int updateRoom(Map<String, String> map) {
		return this.roomDao.updateRoom(map);
	}

	public int delteRoom(String uuId) {
		return this.roomDao.delteRoom(uuId);
	}

	public Map<String, Object> queryRoomByRoomId(String uuId){
		return this.roomDao.queryRoomById(uuId);
	}

    public List<RoomAds> queryRoomAds(String roomNumber) {
        return this.roomDao.queryRoomAds(roomNumber);
    }

    @AllArgsConstructor
    @Data
    public class RoomResult {
    	private String message;
    	private String status;
    }
}
